package jianzhiOffer;

public class Num008 {
    public int minSubArrayLen(int target, int[] nums) {
        int len = Integer.MAX_VALUE;
        int sum = 0;
        for(int l = 0; l < nums.length; l++) {
            sum += nums[l];
            if(sum >= target) {
                len = 1;
                break;
            }
            if(sum > target) {
                break;
            }else {
                int r = l + 1;
                while(sum < target && r < nums.length) {
                    sum += nums[r];
                    r++;
                }
                if(sum >= target) len = Math.min(len,r - l);
            }
            sum = 0;
        }
        return len == Integer.MAX_VALUE? 0 : len;
    }
}
